import axios from 'axios'
import qs from 'qs'

export default {
    namespaced: true,
    actions: {
        addRemark: function ({commit}, params) {
            let {callback} = params;

            params.onget = function ({data}) {
                callback(data.success)
            }

            commit("addRemark", params)
        },
        getAllRemark: function ({commit}, params) {
            let {callback} = params;

            params.onget = function ({data}) {
                callback(data)
            }

            commit("getAll", params)
        },
        deleteRemark: function ({commit}, params) {
            let {callback} = params;

            params.onget = function ({data}) {
                callback(data.success)
            }

            commit("delRemark", params)
        },
    },
    mutations: {
        addRemark: function (state, {content, pageId, userId, onget}) {
            axios.post('/admin/remark', {
                content, pageId, userId
            })
                .then((data) => {
                    onget(data);
                });
        },
        getAll: function (state, {onget, content, pageId, userId, page, size}) {
            axios.get('/admin/remark', {
                params: {
                    content,
                    pageId,
                    userId,
                    page,
                    size
                }
            }).then(res => {
                onget(res);
            })
        },
        delRemark: function (state, {onget, id}) {
            axios.delete('/admin/remark', {params: {id}}).then(data => {
                onget(data)
            })
        }
    }
}